<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2020/12/8
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.5.0.min.js">

    </script>
</head>
<body>
<button onclick="fun()">ajax</button>
<div id="d"></div>
<script>
    function  fun() {
        //获取ajax引擎对象xmlHttpRequest
        var xmlHttpRequest = new XMLHttpRequest();
        //注册回调函数
        xmlHttpRequest.onreadystatechange=function () {
            if (xmlHttpRequest.readyState==4){
                if(xmlHttpRequest.status==200){
                    d.innerHTML=xmlHttpRequest.responseText;
                }if(xmlHttpRequest.status==404){
                    d.innerHTML="路径错误"
                }if (xmlHttpRequest.status==500){
                    d.innerHTML="代码错误"
                }
            }
            alert("xmlHttpRequest"+xmlHttpRequest.readyState);

        };
        //open:打包数据
        xmlHttpRequest.open("get","hello?name=jj");
        //send:发送请求
        xmlHttpRequest.send(null);


    }
</script>
</body>
</html>
